import { mapGetters } from 'vuex'

const mixin = {
  computed: {
    ...mapGetters(['primaryColor', 'bgPath', 'opacityValue', 'httpPath']),
    backgroundPath() {
      const bgCompute = Object.create(null)
      if (typeof this.bgPath === 'number') {
        const path = require.context('@/assets/background', false, /\.png|\.jpg$/)
        const imgPath = path.keys().map((t, idx) => ({ src: path(t), id: idx }))
        bgCompute['background'] = `url(${imgPath[Number(this.bgPath)].src})`
      }
      const reg = /^http|https/
      if (typeof this.bgPath === 'string' && reg.test(this.bgPath)) {
        bgCompute['background'] = `url(${this.bgPath})`
      }
      return bgCompute
    },
    themeOpacity() {
      // 转换
      const opcityCompute = 1 - this.opacityValue >= 0.3 ? 1 - this.opacityValue : 0.3
      return {
        background: `rgba(255, 255, 255, ${opcityCompute})`
      }
    }
  },
  methods: {
    goApp(item) {
      if (!item.path) return this.$message.warning('当前路由不可用！')
      if(item.isFrame==0){
        window.open('javascript:window.name;', '<script>document.write("限学校内网访问!");location.replace("'+item.path+'")<\/script>');
      } else {
        this.$router.push({path: item.path})
      }
    }
  }
}

export { mixin }
